﻿using Eneta.Portal.Forum.Core.Domain.Collections;
using Microsoft.SharePoint;

namespace Eneta.Portal.Forum.Core.Service.Application
{
    public class UserSession
    {
        // Fields
        private CategoryCollection _categoryCollection;
        private readonly SPUser _userDetails;

        // Methods
        private UserSession(SPUser user)
        {
            this._userDetails = user;
        }

        public static UserSession CreateSession(SPUser user)
        {
            return new UserSession(user);
        }

        // Properties
        public CategoryCollection UserCategories
        {
            get
            {
                if (this._categoryCollection == null)
                {
                    this._categoryCollection = RepositoryRegistry.CategoryRepository.GetVisibleCategoriesForUser(this._userDetails);
                }
                return this._categoryCollection;
            }
        }

        public SPUser UserDetails
        {
            get
            {
                return this._userDetails;
            }
        }
    }
}
